import Dao from "../../utils/dao";
import {getLocal, setLocal} from "../../utils/local";
import {file_w} from "../../utils/databaseUtil";

export async function getUserShop() {
    var user = getLocal('app.login_user')
    var query = new AV.Query('shop');
    var user = AV.Object.createWithoutData('user', user.objectId);
    query.equalTo('user', user);
    query.include('user')
    query.include('image')
    var shop = await  query.find().then(res => res[0].toJSON())
    return {
        shop
    }
}

export async function updateShop(_shopData) {
    var shopData = {..._shopData}
    var shop = new Dao('shop')
    shopData.image = file_w(shopData.image.objectId)
    delete shopData.user
    var updateShopResult = await shop.update(shopData.objectId, shopData)
    return updateShopResult
}